package com.hhd.flow.engine.support;

import cn.hutool.core.io.FileUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.*;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class FilePathFlowResource implements FlowResource {
    private String path;

    @Override
    public String getName() {
        return FileUtil.getName(path);
    }

    @Override
    public InputStream getInputStream() {
        try {
            return new FileInputStream(this.path);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public OutputStream getOutputStream() {
        try {
            return new FileOutputStream(this.path);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
